//
//  ShareHandle.m
//  DaFangYa
//
//  Created by lizhenqiang on 16/3/7.
//  Copyright © 2016年 HFKJ_LZQ. All rights reserved.
//

#import "ShareHandle.h"


@implementation ShareHandle

+(NSMutableArray *)getSharePlateList:(UIView *)view andIconArray:(NSArray *)iconArray andTitleArray:(NSArray *)titleArray andPlateArray:(NSArray *)plateArray andPrama:shareParamDic
{
   
    NSMutableArray *activePlatforms = [[NSMutableArray alloc] init];
    for (int i=0;i<titleArray.count;i++) {
        NSString *iconName = iconArray[i];
        NSString *title = titleArray[i];
        NSInteger platformType = [plateArray[i] integerValue];
        SSUIShareActionSheetCustomItem *item = [SSUIShareActionSheetCustomItem itemWithIcon:[UIImage imageNamed:iconName]  label:title onClick:^{//自定义item被点击的处理逻辑
            CDLog(@"=== 自定义item被点击 ===");
            BOOL flag = YES;
            if (platformType == 22 || platformType == 23) {
                if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"weixin://"]]) {
                    flag = YES;
                }
                else
                {
                    flag = NO;
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"尚未安装微信" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                    [alert show];
                }
            }
            else if (platformType == 24 || platformType == 6)
            {
                if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"mqq://"]]) {
                    flag = YES;
                }
                else
                {
                    flag = NO;
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"尚未安装QQ" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                    [alert show];
                }
            }
            if (flag) {
                
                [ShareSDK share:platformType parameters:shareParamDic onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity,  NSError *error){
                    switch (state) {
                        case SSDKResponseStateBegin: {
                            CDLog(@"开始分享");
                            break;
                        }
                        case SSDKResponseStateSuccess: {
                            [MBProgressHUD showSuccess:@"分享成功"];
                            break;
                        }
                        case SSDKResponseStateFail: {
                            [MBProgressHUD showError:@"分享失败"];
                            break;
                        }
                        case SSDKResponseStateCancel: {
                            //                [self.view makeToast:@"分享已取消" duration:1.0 position:@"top"];
                            CDLog(@"分享已取消");
                            break;
                        }
                    }
                }];
            }
        
        }];
        [activePlatforms addObject:item];
    }
    return activePlatforms;
}

@end
